
package com.android.formula.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.formula.R;
import com.android.formula.model.Formula;
import com.android.formula.utils.CommonUtils;
import com.android.formula.utils.Constants;

public class FormulaListAdapter extends TBaseAdapter<Formula> {

    public FormulaListAdapter(Context context, List<Formula> items) {
        super(context, items);
    }

    @Override
    protected View getView(View convertView) {
        convertView = mInflater.inflate(R.layout.item_formula, null, false);
        ViewHolder viewHolder = new ViewHolder(); // new ViewHolder
        viewHolder.init(convertView); // init views in ViewHolder
        convertView.setTag(viewHolder);
        return convertView;
    }

    @Override
    public void freeMemoryView(View v) {
    }

    @Override
    protected void setViews(View view, Formula item) {
        ViewHolder viewHolder = (ViewHolder) view.getTag();
        viewHolder.desTv.setText(item.getFormulaDes());
        CommonUtils.setImageFromDrawable(mContext,
                Constants.IMAGE_TYPE_FORMULA + item.getFormulaId(), viewHolder.itemImageIv);
    }

    protected class ViewHolder {
        public TextView desTv;

        public ImageView itemImageIv;

        public void init(View convertView) {
            itemImageIv = (ImageView) convertView.findViewById(R.id.item_formula_img);
            desTv = (TextView) convertView.findViewById(R.id.item_formula_des_txt);
        }
    }
}
